﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Policlinica;
using OSA.Policlinic.BusinessApplication.Registry;
using NLog;

namespace OSA.Policlinic.UI.WFApplication
{
    public partial class mainForm : Form
    {
        public ShowPatientView patientsView;
        public ShowDoctorView doctorsView;
        public TicketControl ticketControl;
        private IRegistryBusinessApplication registryBusinessApplication;
        private static Logger logger = LogManager.GetCurrentClassLogger();

        public mainForm()
        {
            InitializeComponent();
            registryBusinessApplication = RegistryBusinessApplicationHome.GetInstanse();
            logger.Trace("Форма mainForm успешно инициализирована");
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            if (mainPanel.Controls.Count>0)
            {
                mainPanel.Controls.Clear();
            }
            if(patientsView==null)
            {
                patientsView = new ShowPatientView(this);
                patientsView.Dock = DockStyle.Fill;
            }
            List<Patient> patients = registryBusinessApplication.GetAllPatients();
            patientsView.patientBindingSource.DataSource = patients;
            mainPanel.Controls.Add(patientsView);
            label1.Text = "Список пациентов";
            logger.Debug("Нажата кнопка главной формы 'Пациенты'");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (mainPanel.Controls.Count > 0)
            {
                mainPanel.Controls.Clear();
            }
            if (doctorsView == null)
            {
                doctorsView = new ShowDoctorView(this);
                doctorsView.Dock = DockStyle.Fill;
            }
            List<Doctor> doctors = registryBusinessApplication.GetAllDoctors();
            doctorsView.doctorBindingSource.DataSource = doctors;
            mainPanel.Controls.Add(doctorsView);
            label1.Text = "Список врачей";
            logger.Debug("Нажата кнопка главной формы 'Врачи'");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (mainPanel.Controls.Count > 0)
            {
                mainPanel.Controls.Clear();
            }
            if (ticketControl == null)
            {
                ticketControl = new TicketControl();
                ticketControl.Dock = DockStyle.Fill;
            }
            else
            {
                ticketControl.ClearDoctor();
                ticketControl.ClearPatient();
                ticketControl.ClearService();
            }
            mainPanel.Controls.Add(ticketControl);
            label1.Text = "Выдать новый талон";
            logger.Debug("Нажата кнопка главной формы 'Выдать талон'");
        }
    }
}
